package com.ddf.jpa.boot.controller;

import com.ddf.jpa.boot.entity.User;
import com.ddf.jpa.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DDf on 2018/10/4
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("save")
    public User save(@RequestBody User user) {
        return userService.save(user);
    }

    /**
     * http://localhost:8080/user/list?page=1&size=2&sort=username,asc&sort=password,desc
     * @param pageable
     * @return
     */
    @RequestMapping("list")
    public Page<User> findAll(Pageable pageable) {
        System.out.println(pageable);
        return userService.findAll(pageable);
    }
}
